package com.jxcq.tensquare.rabbit.listener;

import com.jxcq.tensquare.rabbit.utils.SmsUtil;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@RabbitListener(queues = "sms")
public class SmsListener {

  @Autowired
  private SmsUtil smsUtil;

  @Value("${aliyun.sms.template_code}")
  private String template_code;

  @Value("${aliyun.sms.sing_name}")
  private String sing_name;

  @RabbitHandler
  public void executeSms(Map<String,String> map){
    String mobileNum = map.get("mobileNum");
    String verifCode = map.get("verifCode");
    System.out.println("手机号:"+mobileNum);
    System.out.println("验证码:"+verifCode);
    try {
      smsUtil.sendSms(mobileNum,template_code,sing_name,"{\"verifCode\":\""+verifCode+"\"}");
    }catch (Exception e){

    }


  }
}
